/*
 * @Description: 路由配置
 * @Author: hai-27
 * @Date: 2020-02-07 16:23:00
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-06-04 10:24:23
 */
import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

const routes = [
  {
    path: "/",
    name: "首页",
    component: () => import("../views/Home.vue"),
  },
  {
    path: "/error",
    name: "Error",
    component: () => import("../components/Error.vue"),
  },
  // {
  //   path: "/goods",
  //   name: "Goods",
  //   component: () => import("../views/Goods.vue"),
  // },
  {
    path: "/goods",
    name: "特产",
    component: () => import("../views/specialty/index.vue"),
  },
  {
    path: "/about",
    name: "About",
    component: () => import("../views/About.vue"),
  },
  {
    path: "/panda",
    name: "Panda",
    component: () => import("../views/panda/Panda.vue"),
  },
  {
    path: "/login",
    name: "登录",
    component: () => import("../views/login"),
  },
  {
    path: "/registered",
    name: "注册",
    component: () => import("../views/registered"),
  },
  {
    path: "/community",
    name: "社区服务",
    component: () => import("../views/community/Community"),
  },
  {
    path: "/community/education",
    name: "教育培训详情",
    component: () =>
      import("../views/community/components/education/detail/index"),
  },
  {
    path: "/community/medical",
    name: "社区医疗详情",
    component: () =>
      import("../views/community/components/medical/detail/index"),
  },
  {
    path: "/counsel",
    name: "Counsel",
    component: () => import("../views/counsel/Counsel.vue"),
  },
  {
    path: "/counsel/travel",
    name: "Travel",
    component: () =>
      import("../views/counsel/components/travel/detail/Detail.vue"),
  },
  {
    path: "/tourism",
    name: "旅游资源",
    component: () => import("../views/tourism/Tourism.vue"),
  },
  {
    path: "/tourism/culturalAttractions",
    name: "文化景点详情",
    component: () =>
      import(
        "../views/tourism/components/culturalAttractions/detail/Detail.vue"
      ),
  },
  {
    path: "/tourism/famousHotel",
    name: "酒店名宿详情",
    component: () =>
      import("../views/tourism/components/famousHotel/detail/Detail.vue"),
  },
  {
    path: "/tourism/ruralAttraction",
    name: "乡村景点详情",
    component: () =>
      import("../views/tourism/components/ruralAttraction/detail/Detail.vue"),
  },
  {
    path: "/tourism/famousHotel/homeDetail",
    name: "酒店房间详情",
    component: () =>
      import("../views/tourism/components/famousHotel/homeDetail/index"),
  },
  {
    path: "/tourism/dining",
    name: "餐饮美食详情",
    component: () =>
      import("../views/tourism/components/dining/detail/Detail.vue"),
  },
  // {
  //   path: "/goods/details",
  //   name: "Details",
  //   component: () => import("../views/Details.vue"),
  // },
  {
    path: "/goods/details",
    name: "特产详情",
    component: () => import("../views/goodsDetail/index.vue"),
  },
  {
    path: "/settlement",
    name: "结算",
    component: () => import("../views/settlement/index.vue"),
  },
  {
    path: "/pay",
    name: "支付",
    component: () => import("../views/pay/index.vue"),
  },
  {
    path: "/panda",
    name: "大熊猫",
    component: () => import("../views/panda/Panda.vue"),
  },
  {
    path: "/panda/headlines",
    name: "熊猫头条详情",
    component: () =>
      import("../views/panda/components/headlines/detail/Detail.vue"),
  },
  {
    path: "/panda/loveSee",
    name: "爱看熊猫详情",
    component: () =>
      import("../views/panda/components/loveSee/detail/Detail.vue"),
  },
  // {
  //   path: "/goods/details",
  //   name: "Details",
  //   component: () => import("../views/Details.vue"),
  // },
  {
    path: "/shoppingCart",
    name: "ShoppingCart",
    component: () => import("../views/ShoppingCart.vue"),
    meta: {
      requireAuth: true, // 需要验证登录状态
    },
  },
  {
    path: "/collect",
    name: "Collect",
    component: () => import("../views/Collect.vue"),
    meta: {
      requireAuth: true, // 需要验证登录状态
    },
  },
  {
    path: "/order",
    name: "Order",
    component: () => import("../views/user/index.vue"),
    meta: {
      requireAuth: false, // 需要验证登录状态
    },
  },
  {
    path: "/order/userCards",
    name: "userCards",
    component: () => import("../views/userCards/index.vue"),
    meta: {
      requireAuth: false, // 需要验证登录状态
    },
  },
  {
    path: "/order/userCards/logisticsDetails",
    name: "物流详情",
    component: () =>
      import("../views/userCards/components/LogisticsDetails.vue"),
    meta: {
      requireAuth: false, // 需要验证登录状态
    },
  },
  {
    path: "/order/address",
    name: "地址管理",
    component: () => import("../views/addressAdmin/index.vue"),
    meta: {
      requireAuth: false, // 需要验证登录状态
    },
  },
  {
    path: "/order/addressEdit",
    name: "地址管理",
    component: () => import("../views/addresseEdit/index.vue"),
    meta: {
      requireAuth: false, // 需要验证登录状态
    },
  },
  {
    path: "/order/refundDetails",
    name: "退款详情",
    component: () => import("../views/refundDetails/index.vue"),
    meta: {
      requireAuth: false, // 需要验证登录状态
    },
  },
  {
    path: "/order/postComments",
    name: "发布评论",
    component: () => import("../views/postComments/index.vue"),
    meta: {
      requireAuth: false, // 需要验证登录状态
    },
  },
  {
    path: "/confirmOrder",
    name: "ConfirmOrder",
    component: () => import("../views/ConfirmOrder.vue"),
    meta: {
      requireAuth: true, // 需要验证登录状态
    },
  },
];

const router = new Router({
  // base: '/dist',
  // mode: 'history',
  routes,
});

/* 由于Vue-router在3.1之后把$router.push()方法改为了Promise。所以假如没有回调函数，错误信息就会交给全局的路由错误处理。
vue-router先报了一个Uncaught(in promise)的错误(因为push没加回调) ，然后再点击路由的时候才会触发NavigationDuplicated的错误(路由出现的错误，全局错误处理打印了出来)。*/
// 禁止全局路由错误处理打印
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch((err) => err);
};

export default router;
